package com.itheima.controller;

import com.itheima.bean.Student;
import com.itheima.service.demo.StudentServiceDemo;
import org.junit.Test;

import java.util.List;

public class StudentController {

    // 查询所有
    @Test
    public void selectAll(){
        StudentServiceDemo studentServiceDemo = new StudentServiceDemo();
        List<Student> stu = studentServiceDemo.selectAll();
        for (Student student : stu) {
            System.out.println(student);
        }
    }

    // id查询
    @Test
    public void selectById(){
        StudentServiceDemo studentServiceDemo = new StudentServiceDemo();
        Student stu = studentServiceDemo.selectById(2);
        System.out.println(stu);
    }

    // 新增
    @Test
    public void insert(){
        Student stu = new Student(null, "周琦", 25);
        StudentServiceDemo studentServiceDemo = new StudentServiceDemo();
        Integer insert = studentServiceDemo.insert(stu);
        System.out.println(insert);
    }

    // 修改
    @Test
    public void update(){
        Student stu = new Student(8, "周琦", 55);
        StudentServiceDemo studentServiceDemo = new StudentServiceDemo();
        Integer insert = studentServiceDemo.update(stu);
        System.out.println(insert);
    }
    // 新增
    @Test
    public void delete(){
        StudentServiceDemo studentServiceDemo = new StudentServiceDemo();
        Integer insert = studentServiceDemo.delete(8);
        System.out.println(insert);
    }

    @Test
    public void selectByNameOrAge(){
        StudentServiceDemo studentServiceDemo = new StudentServiceDemo();
        List<Student> stu = studentServiceDemo.selectByNameOrAge("张三", 23);
        for (Student student : stu) {
            System.out.println(student);
        }
    }
}
